package com.hspedu.lambda;

import org.junit.jupiter.api.Test;

import java.util.Comparator;
import java.util.function.Consumer;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/3/29
 * @time 20:53
 */
public class LambdaTest1 {
    @Test
    public void test1(){

        Runnable r1 = new Runnable() {
            @Override
            public void run() {
                System.out.println("我爱北京天安门");
            }
        };

        r1.run();

        System.out.println("***********************");

        Runnable r2 = () -> System.out.println("我爱北京故宫");

        r2.run();
    }


    @Test
    public void test2(){
        Consumer<String> consumer = new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        };

        consumer.accept("hello");

        Consumer<String> consumer1 = (String str) -> {
            System.out.println(str);
        };

        consumer1.accept("hello2");

        Consumer<String> consumer2 = (str) -> {
            System.out.println(str);
        };
        consumer2.accept("hello3");

        Consumer<String> consumer3 = s -> {
            System.out.println(s);
        };

        consumer3.accept("hello4");
    }

    @Test
    public void test3(){
        Comparator<Integer> comparator = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                System.out.println(o1);
                System.out.println(o2);
                return o1 - o2;
            }
        };

        Comparator<Integer> comparator1 = (o1, o2) -> {
            System.out.println(o1);
            System.out.println(o2);
            return o1 - o2;
        };
        int i = comparator1.compare(1, 2);
        System.out.println(i);

        Comparator<Integer> comparator2 = (o1, o2) -> o1-o2;
        int i1 = comparator2.compare(1, 2);
        System.out.println(i1);
    }



}
